from django.shortcuts import render
from django.http import HttpResponse
from.models import User
import os
import datetime
from django.conf import settings

# Create your views here.

# def file(request):
#
#
#    return render(request, 'asset/index.html')


def index(request):

    return render(request, 'index.html')

def register(request):

    return render(request, 'register.html')

def UserForm(request):
    # if request.method == "POST":
        email = request.POST.get('email', '')
        nickname = request.POST.get('nickname', '')
        password = request.POST.get('password', '')
        add = User.objects.create(email=email, nickname=nickname, password=password)
        print(email, nickname, password)
        return HttpResponse('注册成功!')

def login(request):
    # if request.method == "POST":
        nickname = request.POST.get('nickname', '')
        password = request.POST.get('password', '')
        print(nickname, password)
        message = "所有字段都必须填写！"
        if nickname and password:
            nickname = nickname.strip()
            try:
                user = models.User.objects.get(nickname=nickname)
                if user.password == password:
                    return redirect('index.html')
                else:
                    message = "密码不正确！"
            except:
                message ="用户名不存在！"
        return render(request, 'index.html')
    # return render(request, 'index.html')







